package com.example.tossednfound;

/**
 * Administrator 
 * Profile details for admin
 */

public class AdminUser extends User{
	/**
	 * creates an admin user from a user
	 * @param user pre-existing user
	 */
	public AdminUser(User user) {
		email = user.email;
		password = user.password;
		address = user.address;
		state = user.state;
		zipcode = user.zipcode;
		country = user.country;
		name = user.name;
	}

	/**
	 * Constructor which takes in all the info to be stored in the AdminUser object
	 * @param emailin Admin's e-mail
	 * @param passwordin Password
	 * @param addressin Street residence location
	 * @param statein State residence
	 * @param zipcodein Zip code
	 * @param countryin Country
	 * @param namein Username
	 */
	public AdminUser(String emailin, String passwordin, String addressin, String statein, int zipcodein, String countryin, String namein ){
		email = emailin;
		password = passwordin;
		address = addressin;
		state = statein;
		zipcode = zipcodein;
		country = countryin;
		name = namein;
	}
	
	/**
	 * removes a user then returns a boolean if successful
	 * @param user user to be removed
	 * @return boolean of the success
	 */
	public static boolean removeUser(User user) {
		return LoginActivity.UserList.remove(user);
	}
	
	/**
	 * locks/ unlocks the user depending on state
	 * @param user the user to be locked/unlocked
	 * @return whether or not it was successful
	 */
	public static boolean toggleLock(User user) {
			User edited = LoginActivity.UserList.get(LoginActivity.UserList.indexOf(user));
			edited.isLocked = !edited.isLocked;
			edited.loginCount = 0;
			return true;
		/*}
		catch(Exception e) {
			return false;
		}*/
	}
	
	/**
	 * makes the user an Admin
	 * @param user the user to be made an admin	
	 * @return whether or not it was successful
	 */
	public static boolean makeAdmin(User user) {
		try {
			AdminUser newAdmin = new AdminUser(user);
			LoginActivity.UserList.remove(user);
			LoginActivity.AdminList.add(newAdmin);
			return true;
		}
		catch(Exception e) {
			return false;
		}
	}
	
}
